package com.zjq.smartdevice.controller.advices;

import com.zjq.smartdevice.dto.R;
import com.zjq.smartdevice.exception.MyBaseException;
import com.zjq.smartdevice.exception.MyErrorCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @User zhangjiaqi
 * @Project project
 * @Package com.zjq.smartdevice.controller.advices
 * @Date 2022/3/17 11:11
 */
@RestControllerAdvice
public class MyErrorAdvice {

    @ExceptionHandler(MyBaseException.class)
    public R processMyBaseException(MyBaseException e) {
        e.printStackTrace();
        return R.getR(e.getCode(), e.getMessage(), null);
    }

    @ExceptionHandler(Exception.class)
    public R processMyBaseException(Exception e) {
        e.printStackTrace();
        return R.getR(MyErrorCode.FAIL, "网络故障,请检查网络", null);
    }



}
